package com.ruoyi.web.controller.supermarket;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.supermarket.domain.SupermarketShelf;
import com.ruoyi.supermarket.service.ISupermarketShelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 超市货架信息Controller
 * 
 * @author faye
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/supermarket/shelf")
public class SupermarketShelfController extends BaseController
{
    @Autowired
    private ISupermarketShelfService supermarketShelfService;

    /**
     * 查询超市货架信息列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:shelf:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketShelf supermarketShelf)
    {
        startPage();
        List<SupermarketShelf> list = supermarketShelfService.selectSupermarketShelfList(supermarketShelf);
        return getDataTable(list);
    }

    /**
     * 导出超市货架信息列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:shelf:export')")
    @Log(title = "超市货架信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketShelf supermarketShelf)
    {
        List<SupermarketShelf> list = supermarketShelfService.selectSupermarketShelfList(supermarketShelf);
        ExcelUtil<SupermarketShelf> util = new ExcelUtil<SupermarketShelf>(SupermarketShelf.class);
        util.exportExcel(response, list, "超市货架信息数据");
    }

    /**
     * 获取超市货架信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:shelf:query')")
    @GetMapping(value = "/{shelfId}")
    public AjaxResult getInfo(@PathVariable("shelfId") Long shelfId)
    {
        return success(supermarketShelfService.selectSupermarketShelfByShelfId(shelfId));
    }

    /**
     * 新增超市货架信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:shelf:add')")
    @Log(title = "超市货架信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketShelf supermarketShelf)
    {
        return toAjax(supermarketShelfService.insertSupermarketShelf(supermarketShelf));
    }

    /**
     * 修改超市货架信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:shelf:edit')")
    @Log(title = "超市货架信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketShelf supermarketShelf)
    {
        return toAjax(supermarketShelfService.updateSupermarketShelf(supermarketShelf));
    }

    /**
     * 删除超市货架信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:shelf:remove')")
    @Log(title = "超市货架信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shelfIds}")
    public AjaxResult remove(@PathVariable Long[] shelfIds)
    {
        return toAjax(supermarketShelfService.deleteSupermarketShelfByShelfIds(shelfIds));
    }
}
